//
//  UIImage+Extension.swift
//  Hweibome
//
//  Created by 何川 on 15/12/9.
//  Copyright © 2015年 hechuan. All rights reserved.
//

import UIKit

extension UIImage
{
    class func getLaunchImage() ->UIImage? {
        let dict = NSBundle.mainBundle().infoDictionary
        guard let images = dict?["UILaunchImages"]as?[[String:AnyObject]] else
        {
            return nil
        }
        let screenSize = UIScreen.mainScreen().bounds.size
        for imageDict in images
        {
            guard let sizeString = imageDict["UILaunchImageSize"] as? String else
            {
                break
            }
            let size = CGSizeFromString(sizeString)
            
            if CGSizeEqualToSize(screenSize, size)
            {
                let image = UIImage(named: (imageDict["UILaunchImageName"] as! String))
                return image
            }
        }
        return nil
    }
    
    class func screentShot() -> UIImage {
        let window = UIApplication.sharedApplication().keyWindow!
        //begain
        UIGraphicsBeginImageContext(window.size) //using frameExtension
        
        window.drawViewHierarchyInRect(window.bounds, afterScreenUpdates: false)
        //get image
        let image = UIGraphicsGetImageFromCurrentImageContext()
        //close context
        UIGraphicsEndImageContext()
        return image
    }
    
//    let imageView = UIImageView(image: UIImage.getLaunchImage()!)
//    
//    view.addSubview(imageView)
//    
//    UIView.animateWithDuration(3, animations: { () -> Void in
//    
//    // 执行放大并透明
//    imageView.transform = CGAffineTransformMakeScale(3, 3)
//    imageView.alpha = 0
//    
//    }) { (_) -> Void in
//    imageView.removeFromSuperview()
//    }
}